package es.ats.codington.festival.services;

import java.io.IOException;
import java.sql.Connection;
import java.sql.SQLException;
import java.util.ArrayList;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;

import es.ats.codington.festival.daos.DAOManager;
import es.ats.codington.festival.daos.EventDAOImpl;
import es.ats.codington.festival.domain.Event;
import es.ats.codington.festival.interfaces.daos.iEventDAO;
import es.ats.codington.festival.interfaces.services.iCreateEvent;
import es.ats.codington.festival.interfaces.services.iGetIdsEvent;
import es.ats.codington.festival.interfaces.services.iViewAllEvents;
import es.ats.codington.festival.interfaces.services.iViewEvent;
import es.ats.codington.festival.interfaces.services.iViewMyEvents;
import es.ats.codington.festival.utils.FERSDataConnection.FersDC;


/**
 * The Class EventService.
 *
 * @author CODINGTONPOJO
 */
	
public class EventService implements  iViewEvent, iViewMyEvents, iGetIdsEvent, iCreateEvent {
	
	/** The event dao. */
	private iEventDAO eventDAO;

	
	/**
	 * Instantiates a new event service.
	 */
	public EventService(){
		ApplicationContext ctx = new ClassPathXmlApplicationContext("beans.xml");  
		DAOManager daoManager = (DAOManager) ctx.getBean("daoManager");
		this.eventDAO = daoManager.getEventDAO();
	}

	
	
	/* (non-Javadoc)
	 * @see es.ats.codington.festival.interfaces.services.iViewEvent#viewEvent(int)
	 */
	@Override
	public Event viewEvent(int idevent) throws Exception {
		Event event = null;
		
		try{

			event=eventDAO.viewEvent(idevent);
			
			}catch (Exception ex){
				System.out.println("Error Exception with message: " + ex.getMessage());

			}

		return event;
	}
		
	
	
	/* (non-Javadoc)
	 * @see es.ats.codington.festival.interfaces.services.iViewMyEvents#viewMyEvent(int)
	 */
	@Override
	public ArrayList<Integer> viewMyEvent(int idvisitor) throws Exception {
		
		ArrayList<Integer> idMyEvents = new ArrayList<Integer>();
		try{

			idMyEvents = eventDAO.viewMyEvents(idvisitor);
			
			}catch (Exception ex){
				System.out.println("Error Exception with message: " + ex.getMessage());

			}

			
		return idMyEvents;
		
	}
	
/* (non-Javadoc)
 * @see es.ats.codington.festival.interfaces.services.iGetIdsEvent#getIdsEvent(int)
 */
public ArrayList<Integer> getIdsEvent(int idplace) throws Exception {
		
	ArrayList<Integer> idsEventByType= new ArrayList<Integer>();
		try{

			idsEventByType = eventDAO.getIdsEvent(idplace);
			
			}catch (Exception ex){
				System.out.println("Error Exception with message: " + ex.getMessage());

			}
			
		return idsEventByType;
		
	}
		
		/* (non-Javadoc)
		 * @see es.ats.codington.festival.interfaces.services.iCreateEvent#createEvent(es.ats.codington.festival.domain.Event)
		 */
		@Override
		public boolean createEvent(Event event1) throws Exception {
			boolean ins=false;
			
		try{
			
			ins=eventDAO.createEvent(event1);
		
			}catch (Exception ex){
				System.out.println("Error Exception with message: " + ex.getMessage());
			
				}

			return ins;
		}

}


